using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RAG.Domain.Repositories;
using RAG.Infrastructure.Data;
using RAG.Infrastructure.Repositories;

namespace RAG.Infrastructure;

public static class ServicesCollectionExtensition
{
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
    {

        var conString=configuration.GetConnectionString("pgsql");
        // 配置数据库上下文
        services.AddDbContext<RagDbContext>(options =>
        {
           options.UseNpgsql(conString);
        });

        // 注册通用仓储
        services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
        


        return services;
    }
}